package ruoyi.example;

import cn.hutool.json.JSONUtil;
import openapi.sdk.common.model.KeyPair;
import openapi.sdk.common.util.AsymmetricCryUtil;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import ruoyi.example.client.UserApiTest;
import ruoyi.example.client.UserApiTest2;

/**
 * 项目启动
 *
 * @author wanghuidong
 */
@SpringBootApplication
public class ClientApplication {

    public static void main(String[] args) {

        ConfigurableApplicationContext context = new SpringApplicationBuilder().sources(ClientApplication.class).web(WebApplicationType.NONE).run(args);
        long startTime = System.nanoTime();

        // 方式一
        UserApiTest test = context.getBean(UserApiTest.class);
        test.getUserById();

        // 方式二
        UserApiTest2 test2 = context.getBean(UserApiTest2.class);
        test2.getUserById();

        long endTime = System.nanoTime();
        System.out.println("耗时：" + (endTime - startTime) / 100_0000 + "ms");
    }

    /**
     * 生成密钥对
     */
    public void generateKeys() {
        KeyPair keyPair = AsymmetricCryUtil.generateRSAKeys();
        System.out.println("RSA密钥对：\n" + JSONUtil.toJsonStr(keyPair));

        keyPair = AsymmetricCryUtil.generateSM2Keys();
        System.out.println("SM2密钥对：\n" + JSONUtil.toJsonStr(keyPair));
    }
}
